﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Filter;
using System.Linq.Expressions;
using COFE.Data.Utils.ThirdParty;
using COFE.Data.Utils;

namespace COFE.Data.Filter
{
    public class FileNameEntryFilterExpression :
         EntryFilterExpression<COFE.Core.Filter.FileNameEntryFilter>
    {
        public FileNameEntryFilterExpression()
            : base()
        {

        }

        public override Expression<Func<Entry, bool>> getExpression(
            IEntryFilter filter, IOptionFilter[] options)
        {
            var entryFilter = filter as COFE.Core.Filter.FileNameEntryFilter;
            string containStr = entryFilter.Value
                .Replace(".*", "")
                .Replace("*", "").Replace("?", "");
            
            Expression<Func<Entry, bool>> exp = e => true;
            
            if (!(String.IsNullOrEmpty(containStr)))
                exp = (e) => e.Label.ToLower().Contains(containStr.ToLower());

            if (filter.Negative)
                return exp.Not();
            return exp;
        }
       

    }
}
